home *** CD-ROM | disk | FTP | other *** search
- unit uEditContact;
-
- {
- *******************************************************************************
- * Descriptions: Main Unit for FMA
- * $Source: /cvsroot/fma/fma/uEditContact.pas,v $
- * $Locker: $
- *
- * Todo:
- * - add picture and sound support
- *
- * Change Log:
- * $Log: uEditContact.pas,v $
- * Revision 1.20.6.1 2004/10/14 16:43:24 z_stoichev
- * Bugfixes
- *
- * Revision 1.20 2004/07/06 20:13:58 lordlarry
- * Fixed Changing email address has no effect
- *
- * Revision 1.19 2004/07/06 14:06:52 z_stoichev
- * - Added Personalization default contact image.
- *
- * Revision 1.18 2004/07/01 14:41:30 z_stoichev
- * Outlook summary fille in.
- * Save notes renamed to export.
- *
- * Revision 1.17 2004/06/29 10:43:20 z_stoichev
- * Added Call notes support
- * More prefferences added
- *
- * Revision 1.16 2004/06/26 16:45:52 lordlarry
- * Implemented Unlinking of Synced contact
- *
- * Revision 1.15 2004/06/23 13:50:39 z_stoichev
- * Outlook updates
- *
- * Revision 1.14 2004/06/18 13:49:37 z_stoichev
- * - Added Edit Contact UI sanity feedback.
- * - Added Edit Contact DisplayName auto-update.
- *
- * Revision 1.13 2004/06/15 13:47:01 z_stoichev
- * Outlook DisplayName, FileAs, GUID support
- * Interface Bugfixes
- *
- * Revision 1.12 2004/05/21 14:39:47 z_stoichev
- * Fixed Contact name changes not saved
- * Added Contact Display name support
- *
- * Revision 1.11 2004/05/19 18:34:15 z_stoichev
- * Build 0.1.0.35c
- *
- * Revision 1.10 2004/04/01 15:07:47 z_stoichev
- * Apply button fixes
- *
- * Revision 1.9 2004/03/26 18:37:39 z_stoichev
- * Build 0.1.0.35 RC5
- *
- * Revision 1.8 2004/03/11 12:44:59 z_stoichev
- * Fixed Font Charset.
- *
- * Revision 1.7 2004/01/28 17:12:14 z_stoichev
- * Allow editing ME when no obex.
- *
- * Revision 1.6 2003/12/11 12:39:55 z_stoichev
- * Fixed upload and select issue.
- *
- * Revision 1.5 2003/12/02 16:39:16 z_stoichev
- * Fixed error when editing own card.
- *
- * Revision 1.4 2003/12/01 16:01:38 z_stoichev
- * Support for Own card editing.
- * Auto set picture on upload.
- *
- * Revision 1.3 2003/11/28 09:38:07 z_stoichev
- * Merged with branch-release-1-1 (Fma 0.10.28c)
- *
- * Revision 1.2.2.13 2003/11/26 12:25:01 z_stoichev
- * Allow 'p' char (pause) into numbers.
- * Tab settings update on activate fixed.
- *
- * Revision 1.2.2.12 2003/11/21 13:24:15 z_stoichev
- * Fixed Show window caption, when names are empty.
- * Allow creating new contact with default cell number.
- *
- * Revision 1.2.2.11 2003/11/19 13:28:40 z_stoichev
- * Cell word changed to Mobile.
- *
- * Revision 1.2.2.10 2003/11/19 12:55:00 z_stoichev
- * Allow # and * in numbers.
- *
- * Revision 1.2.2.9 2003/11/11 18:12:23 z_stoichev
- * Contact personalization changes.
- *
- * Revision 1.2.2.8 2003/11/11 13:24:02 z_stoichev
- * Add personalization support.
- *
- * Revision 1.2.2.7 2003/11/10 14:03:09 z_stoichev
- * RC3
- *
- * Revision 1.2.2.6 2003/11/07 13:56:49 z_stoichev
- * Add support for editing SIM records.
- *
- * Revision 1.2.2.5 2003/11/07 11:16:54 z_stoichev
- * Fixed edit contact do not apply changes.
- *
- * Revision 1.2.2.4 2003/10/30 13:25:46 z_stoichev
- * Fixed phone numbers sanity check.
- * Added Beep on wrong char input.
- *
- * Revision 1.2.2.3 2003/10/28 12:46:56 z_stoichev
- * Add default number selection.
- * Dont update contact as modified if only
- * custom Fma data is modified.
- *
- * Revision 1.2.2.2 2003/10/27 15:23:56 z_stoichev
- * Clear cached information button is added.
- *
- * Revision 1.2.2.1 2003/10/27 07:22:54 z_stoichev
- * Build 0.1.0 RC1 Initial Checkin.
- *
- * Revision 1.2 2003/10/24 12:32:21 z_stoichev
- * Full name is updated on name, surname change.
- * Show some default picture and sound infos.
- * Fixed: Name + surname length + space = 30.
- *
- * Revision 1.1 2003/10/23 11:32:41 z_stoichev
- * Initial checkin.
- *
- *
- *
- }
-
- interface
-
- uses
- Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
- Dialogs, ExtCtrls, StdCtrls, TntStdCtrls, ComCtrls, Buttons, uSyncPhonebook,
- Menus, TntComCtrls, MPlayer, GR32_Image, uContactSync;
-
- type
- TfrmEditContact = class(TForm)
- PageControl1: TPageControl;
- TabSheet1: TTabSheet;
- Image1: TImage;
- Bevel1: TBevel;
- Label1: TLabel;
- txtTitle: TTntEdit;
- txtName: TTntEdit;
- Label2: TLabel;
- Label4: TLabel;
- txtOrganization: TTntEdit;
- txtEmail: TTntEdit;
- Label5: TLabel;
- Bevel2: TBevel;
- Label6: TLabel;
- txtHome: TTntEdit;
- Label7: TLabel;
- txtWork: TTntEdit;
- Label8: TLabel;
- txtCell: TTntEdit;
- Label9: TLabel;
- txtFax: TTntEdit;
- Label10: TLabel;
- txtOther: TTntEdit;
- TabSheet2: TTabSheet;
- OkButton: TButton;
- CancelButton: TButton;
- ApplyButton: TButton;
- GroupBox1: TGroupBox;
- Panel1: TPanel;
- btnPicSel: TButton;
- Label12: TLabel;
- Label13: TLabel;
- lblPicDim: TLabel;
- Label15: TLabel;
- imgDim: TImage;
- lblPicName: TLabel;
- lblPicSize: TLabel;
- btnPicNew: TButton;
- GroupBox2: TGroupBox;
- btnPicDel: TButton;
- Label14: TLabel;
- Label16: TLabel;
- Label17: TLabel;
- btnSndNew: TButton;
- btnSndDel: TButton;
- btnSndSel: TButton;
- imgSnd: TImage;
- lblSndType: TLabel;
- lblSndName: TLabel;
- lblSndSize: TLabel;
- Label11: TLabel;
- lblPicPal: TLabel;
- TabSheet3: TTabSheet;
- Label18: TLabel;
- ResetButton: TButton;
- Label19: TLabel;
- TabSheet4: TTabSheet;
- GroupBox3: TGroupBox;
- cbDefaultNum: TComboBox;
- Label20: TLabel;
- Label21: TLabel;
- Label22: TLabel;
- Label23: TLabel;
- PopupMenu1: TPopupMenu;
- MediaPlayer1: TMediaPlayer;
- SelImage: TImage32;
- txtDisplayAs: TTntComboBox;
- TabSheet5: TTabSheet;
- GroupBox4: TGroupBox;
- txtContactDataID: TTntEdit;
- Label3: TLabel;
- Button1: TButton;
- Label26: TLabel;
- GroupBox5: TGroupBox;
- txtFileAs: TTntEdit;
- Label25: TLabel;
- Label27: TLabel;
- Label24: TLabel;
- Label28: TLabel;
- TabSheet6: TTabSheet;
- GroupBox6: TGroupBox;
- CheckBox1: TCheckBox;
- GroupBox7: TGroupBox;
- MemoNotes: TTntMemo;
- btNotesClear: TButton;
- btNotesSave: TButton;
- SaveDialog1: TSaveDialog;
- GroupBox8: TGroupBox;
- RadioButton1: TRadioButton;
- RadioButton2: TRadioButton;
- RadioButton3: TRadioButton;
- Button2: TButton;
- MemoDetails: TTntMemo;
- procedure FormCreate(Sender: TObject);
- procedure FormShow(Sender: TObject);
- procedure txtChange(Sender: TObject);
- procedure customChange(Sender: TObject);
- procedure ApplyButtonClick(Sender: TObject);
- procedure OkButtonClick(Sender: TObject);
- procedure txtTelKeyPress(Sender: TObject; var Key: Char);
- procedure ResetButtonClick(Sender: TObject);
- procedure TabSheet4Show(Sender: TObject);
- procedure txtPhoneChange(Sender: TObject);
- procedure txtPhoneEnter(Sender: TObject);
- procedure btnPicSelClick(Sender: TObject);
- procedure btnSndSelClick(Sender: TObject);
- procedure OnPicSelClick(Sender: TObject);
- procedure OnSndSelClick(Sender: TObject);
- procedure btnPicDelClick(Sender: TObject);
- procedure btnSndDelClick(Sender: TObject);
- procedure MediaPlayer1Click(Sender: TObject; Button: TMPBtnType;
- var DoDefault: Boolean);
- procedure PageControl1Change(Sender: TObject);
- procedure btnUploadClick(Sender: TObject);
- procedure txtChangeEditAs(Sender: TObject);
- procedure OnChangeAsEnter(Sender: TObject);
- procedure Button1Click(Sender: TObject);
- procedure btNotesClearClick(Sender: TObject);
- procedure MemoNotesChange(Sender: TObject);
- procedure btNotesSaveClick(Sender: TObject);
- procedure txtEmailChange(Sender: TObject);
- private
- { Private declarations }
- FPhonePrev: string;
- FPrevChangeAs: WideString;
- FUseSIMMode,FLoadingData,FUseOwnMode: boolean;
- FCustomImage: Boolean;
- procedure DoSanityCheck;
- procedure LoadContactData;
- procedure SaveContactData;
- procedure ShowFullName(Modified: WideString = '');
- procedure FillDisplayNameList;
- procedure UpdateDefNum(SetTo: integer = 0);
- procedure UpdatePersonalize;
- procedure Set_UseSIMMode(const Value: boolean);
- procedure Set_UseOwnMode(const Value: boolean);
- procedure SelectFile(Pos: TPoint; FileType: byte; Selected: WideString = '');
- procedure SyncContactsError(Sender: TObject; const Message: String);
- procedure SyncContactsConfirm(Sender: TObject; Contact: TContact;
- Action: TContactAction; const Description: WideString;
- var Confirmed: Boolean);
- procedure Set_CustomImage(const Value: Boolean);
- public
- MaxFullNameLen: integer;
- IsNew,Modified,customModified: boolean;
- contact: TContactData;
- published
- procedure LoadAndMergeWith(AContact: TContactData);
- property UseSIMMode: boolean read FUseSIMMode write Set_UseSIMMode default False;
- property UseOwnMode: boolean read FUseOwnMode write Set_UseOwnMode default False;
- property IsCustomImage: Boolean read FCustomImage write Set_CustomImage;
- end;
-
- var
- frmEditContact: TfrmEditContact;
-
- implementation
-
- uses Unit1;
-
- {$R *.dfm}
-
- procedure TfrmEditContact.FormCreate(Sender: TObject);
- begin
- lblPicDim.Left := imgDim.Left + imgDim.Width + 4;
- lblPicName.Left := Label13.Left + Label13.Width + 4;
- lblPicSize.Left := Label15.Left + Label15.Width + 4;
- lblPicPal.Left := Label11.Left + Label11.Width + 4;
- lblSndType.Left := imgSnd.Left + imgSnd.Width + 4;
- lblSndName.Left := Label14.Left + Label14.Width + 4;
- lblSndSize.Left := Label16.Left + Label16.Width + 4;
- {$IFNDEF VER150}
- Form1.ThemeManager1.CollectForms(Self);
- {$ENDIF}
- end;
-
- procedure TfrmEditContact.FormShow(Sender: TObject);
- begin
- MaxFullNameLen := txtName.MaxLength;
- LoadContactData;
- PageControl1.ActivePageIndex := 0;
- txtName.SetFocus;
- end;
-
- procedure TfrmEditContact.LoadContactData;
- var
- c: TColor;
- b: boolean;
- w: WideString;
- procedure UpdateTelView(var Item: TTntEdit);
- begin
- { Always enable, and disable only empty Edits }
- if b or (Item.Text = '') then begin
- Item.Enabled := b;
- Item.Color := c;
- end;
- end;
- begin
- FLoadingData := True;
- try
- FPrevChangeAs := '';
- FPhonePrev := '';
- if FUseSIMMode then c := clBtnFace else c := clWindow;
- b := not FUseSIMMode;
- // contact
- txtTitle.Text := contact.title;
- w := contact.name;
- if contact.surname <> '' then
- w := w + ' ' + contact.surname; // do not use GetContactFullName here!
- txtName.Text := w;
- txtContactDataID.Text := GUIDToString(contact.CDID);
- txtFileAs.Text := contact.displayname;
- txtDisplayAs.Text := contact.displayname;
- txtOrganization.Text := contact.org;
- txtEmail.Text := contact.email;
- txtHome.Text := contact.home;
- txtWork.Text := contact.work;
- txtCell.Text := contact.cell;
- txtFax.Text := contact.fax;
- txtOther.Text := contact.other;
- ShowFullName;
- FillDisplayNameList;
- if not (FUseSIMMode or FUseOwnMode) then begin
- // Personalize, will fill data on tabsheet open
- btnPicDel.Click;
- btnSndDel.Click;
- // Preferences
- UpdateDefNum(contact.DefaultIndex);
- end;
- { Leave only used field for editing, or enable all fields for new contacts }
- if FUseSIMMode then begin
- if (txtCell.Text <> '') or (txtHome.Text <> '') or (txtWork.Text <> '') or
- (txtFax.Text <> '') or (txtOther.Text <> '') then begin
- UpdateTelView(txtCell);
- UpdateTelView(txtHome);
- UpdateTelView(txtWork);
- UpdateTelView(txtFax);
- UpdateTelView(txtOther);
- end
- else if not Form1.frmSIMEdit.IsMEMode then begin
- { For SIM card enable only cell phone }
- UpdateTelView(txtHome);
- UpdateTelView(txtWork);
- UpdateTelView(txtFax);
- UpdateTelView(txtOther);
- end;
- end
- else begin
- GetContactNotes(@contact,MemoNotes.Lines);
- MemoNotesChange(nil);
- GetContactDetails(@contact,MemoDetails.Lines);
- end;
- finally
- FLoadingData := False;
- end;
- // done
- ResetButton.Enabled := not IsNew;
- ApplyButton.Enabled := False;
- Modified := False;
- customModified := False;
- end;
-
- procedure TfrmEditContact.SaveContactData;
- var
- i: integer;
- s,a: WideString;
- begin
- contact.title := txtTitle.text;
- contact.org := txtOrganization.text;
- { Update contact name and surname }
- a := GetContactFullName(@contact);
- s := Trim(txtName.text);
- i := Pos(' ',s);
- if i = 0 then begin
- contact.name := s;
- contact.surname := '';
- end
- else begin
- contact.name := Copy(s,1,i-1);
- Delete(s,1,i);
- contact.surname := Trim(s);
- end;
- (* Commented out since will keep DisplayName as fma internal setting
- s := GetContactFullName(@contact);
- if WideCompareText(a,s) <> 0 then
- { If name/surname are changed, reset display name, since SE T610
- doesnt support displayname vCard peoperty }
- txtDisplayAs.Text := s;
- *)
- contact.displayname := txtDisplayAs.Text;
- contact.email := txtEmail.text;
- contact.home := txtHome.text;
- contact.work := txtWork.text;
- contact.cell := txtCell.text;
- contact.fax := txtFax.text;
- contact.other := txtOther.text;
- if not (FUseSIMMode or FUseOwnMode) then begin
- contact.DefaultIndex := cbDefaultNum.ItemIndex;
- contact.picture := lblPicName.Caption;
- contact.sound := lblSndName.Caption;
- contact.CDID := StringToGUID(txtContactDataID.Text);
- end;
- SetContactNotes(@contact,MemoNotes.Lines);
- { Dont change modified flags here, since we'll use them in SyncPhonebook.
- Only disable apply button. }
- ApplyButton.Enabled := False;
- end;
-
- procedure TfrmEditContact.txtChange(Sender: TObject);
- begin
- ApplyButton.Enabled := not IsNew;
- customModified := True;
- end;
-
- procedure TfrmEditContact.ApplyButtonClick(Sender: TObject);
- begin
- DoSanityCheck;
- SaveContactData;
- end;
-
- procedure TfrmEditContact.OkButtonClick(Sender: TObject);
- begin
- DoSanityCheck;
- if ApplyButton.Enabled or IsNew then
- SaveContactData;
- ModalResult := mrOk;
- end;
-
- procedure TfrmEditContact.txtTelKeyPress(Sender: TObject; var Key: Char);
- begin
- case ord(Key) of
- 8, 48..57: ;
- 35, 42: ; // # and * (for special service numbers)
- 3, 22, 24, 26: ; //escape CTRL+C,V,X,Z ;)
- 43: with (Sender as TTntEdit) do begin
- if (Pos('+',Text) <> 0) or (SelStart <> 0) then begin
- Key := #0; //only the first char can be '+'
- Beep;
- end;
- end;
- 112: ; // p (pause)
- else begin
- Key := #0;
- Beep;
- end;
- end;
- end;
-
- procedure TfrmEditContact.ResetButtonClick(Sender: TObject);
- begin
- FillChar(contact.Position,SizeOf(contact.Position),0);
- ApplyButton.Enabled := not IsNew;
- customModified := True;
- end;
-
- procedure TfrmEditContact.TabSheet4Show(Sender: TObject);
- begin
- UpdateDefNum;
- end;
-
- procedure TfrmEditContact.UpdateDefNum(SetTo: integer);
- var
- selpos: integer;
- begin
- if SetTo = 0 then selpos := cbDefaultNum.ItemIndex else selpos := SetTo;
- cbDefaultNum.Items.Clear;
- // see TContactData.DefaultIndex
- // 0 none;1 cell;2 work;3 home;4 other
- cbDefaultNum.Items.Add('None');
- if txtCell.Text <> '' then cbDefaultNum.Items.Add('Mobile ['+txtCell.Text+']');
- if txtWork.Text <> '' then cbDefaultNum.Items.Add('Work ['+txtWork.Text+']');
- if txtHome.Text <> '' then cbDefaultNum.Items.Add('Home ['+txtHome.Text+']');
- if txtOther.Text <> '' then cbDefaultNum.Items.Add('Other ['+txtOther.Text+']');
- if (selpos < 0) or (selpos >= cbDefaultNum.Items.Count) then
- selpos := 0; // Out of range goes to None
- cbDefaultNum.ItemIndex := selpos;
- end;
-
- procedure TfrmEditContact.customChange(Sender: TObject);
- begin
- ApplyButton.Enabled := not IsNew;
- customModified := True;
- end;
-
- procedure TfrmEditContact.txtPhoneChange(Sender: TObject);
- const
- sem: boolean = False;
- var
- i: integer;
- s: string;
- b: boolean;
- begin
- if {not FLoadingData and} not sem then
- try
- sem := true;
- with (Sender as TTntEdit) do begin
- b := False;
- s := Text;
- i := 1;
- while i <= Length(s) do begin
- if ((i > 1) and (s[1] = '+') and (s[i] = '+')) or
- (Pos('+',s) > 1) or not (s[i] in ['+','0'..'9','#','*','p']) then begin
- Delete(s,i,1);
- b := True;
- end
- else
- inc(i);
- end;
- if s <> Text then Text := s;
- if s <> FPhonePrev then begin
- FPhonePrev := s;
- ApplyButton.Enabled := not IsNew;
- Self.Modified := True;
- end;
- if b then Beep;
- end;
- finally
- sem := False;
- end;
- end;
-
- procedure TfrmEditContact.txtPhoneEnter(Sender: TObject);
- begin
- FPhonePrev := (Sender as TTntEdit).Text;
- end;
-
- procedure TfrmEditContact.Set_UseSIMMode(const Value: boolean);
- var
- i: integer;
- c: TColor;
- b: boolean;
- begin
- FUseSIMMode := Value;
- if Value then c := clBtnFace else c := clWindow;
- b := not Value;
- txtTitle.Enabled := b;
- txtTitle.Color := c;
- txtOrganization.Enabled := b;
- txtOrganization.Color := c;
- txtEmail.Enabled := b;
- txtEmail.Color := c;
- txtDisplayAs.Enabled := b;
- txtDisplayAs.Color := c;
- { In SIM mode leave only General tab visible }
- for i := 1 to PageControl1.PageCount-1 do
- PageControl1.Pages[i].TabVisible := b;
- end;
-
- procedure TfrmEditContact.SelectFile(Pos: TPoint; FileType: byte; Selected: WideString);
- var
- m: TMenuItem;
- Node,Item: TTntTreeNode;
- Offline: boolean;
- What: string;
- ImgIdx: integer;
- rec: TSearchRec;
- begin
- Offline := not Form1.FConnected or not Form1.FUseObex;
- PopupMenu1.Items.Clear;
- if Offline then begin
- case FileType of
- 0: What := '\pic\*.*';
- 1: What := '\snd\*.*';
- end;
- if FindFirst(ExePath+'data\'+Form1.PhoneIdentity+What,faAnyFile,rec) = 0 then
- try
- repeat
- ImgIdx := Form1.ExplorerFindExtImage(ExtractFileExt(rec.Name));
- if ImgIdx = -1 then continue;
- m := TMenuItem.Create(nil);
- try
- m.AutoHotkeys := maManual;
- m.Caption := rec.Name;
- m.Tag := rec.Size;
- m.Hint := rec.Name; // ignored in offline mode
- m.ImageIndex := ImgIdx;
- case FileType of
- 0: m.OnClick := OnPicSelClick;
- 1: m.OnClick := OnSndSelClick;
- end;
- if Selected <> '' then begin
- if WideCompareText(rec.Name,Selected) = 0 then begin
- m.Click;
- m.Free;
- break;
- end;
- m.Free;
- end
- else
- PopupMenu1.Items.Add(m);
- except
- m.Free;
- end;
- until FindNext(rec) <> 0;
- finally
- FindClose(rec);
- end;
- end
- else begin
- Node := Form1.FindObexFolderNode(FileType);
- if Assigned(Node) then begin
- Item := Node.getFirstChild;
- while Item <> nil do
- try
- m := TMenuItem.Create(nil);
- try
- m.AutoHotkeys := maManual;
- m.Caption := Item.Text;
- m.Tag := Item.StateIndex;
- m.Hint := Node.Text + '/' + Item.Text;
- m.ImageIndex := Item.ImageIndex;
- case FileType of
- 0: m.OnClick := OnPicSelClick;
- 1: m.OnClick := OnSndSelClick;
- end;
- if Selected <> '' then begin
- if WideCompareText(Item.Text,Selected) = 0 then begin
- m.Click;
- m.Free;
- break;
- end;
- m.Free;
- end
- else
- PopupMenu1.Items.Add(m);
- except
- m.Free;
- end;
- finally
- Item := Node.GetNextChild(Item);
- end;
- end;
- end;
- if PopupMenu1.Items.Count = 0 then begin
- MessageBeep(MB_ICONASTERISK);
- MessageDlg('You should refresh Explorer Files folder prior using this feature.'#13#13+
- 'Note that this is currently not supported if you are using IR connection.',mtInformation,[mbOk],0);
- end
- else
- PopupMenu1.Popup(pos.X,pos.Y);
- end;
-
- procedure TfrmEditContact.btnPicSelClick(Sender: TObject);
- var
- p: TPoint;
- begin
- p := btnPicSel.ClientToScreen(Point(0,btnPicSel.Height));
- SelectFile(p,0);
- end;
-
- procedure TfrmEditContact.btnSndSelClick(Sender: TObject);
- var
- p: TPoint;
- begin
- p := btnSndSel.ClientToScreen(Point(0,btnSndSel.Height));
- SelectFile(p,1);
- end;
-
- procedure TfrmEditContact.OnPicSelClick(Sender: TObject);
- var
- Filename,Fullpath,Objectname: WideString;
- Filesize: integer;
- begin
- btnPicSel.Enabled := False;
- btnSndSel.Enabled := False;
- try
- Objectname := (Sender as TMenuItem).Hint;
- Filename := (Sender as TMenuItem).Caption;
- Filesize := (Sender as TMenuItem).Tag;
- Fullpath := ExePath+'data\'+Form1.PhoneIdentity+'\pic\';
-
- lblPicDim.Caption := '';
- lblPicSize.Caption := '';
- lblPicPal.Caption := '';
- lblPicName.Caption := '(Loading '+Filename+'...)';
-
- try
- ForceDirectories(Fullpath);
- if Form1.FConnected and Form1.FUseObex and not FileExists(Fullpath+Filename) then
- Form1.ObexGetFile(Fullpath+Filename,Objectname,False);
-
- SelImage.Bitmap.LoadFromFile(Fullpath+Filename);
- IsCustomImage := True;
- btnPicDel.Enabled := True;
- except
- btnPicDel.Click;
- raise;
- end;
-
- lblPicName.Caption := Filename;
- lblPicDim.Caption := Format('%dx%d (%dx%d pixels)',[SelImage.Width,SelImage.Height,
- SelImage.Bitmap.BitmapInfo.bmiHeader.biWidth,-SelImage.Bitmap.BitmapInfo.bmiHeader.biHeight]);
- lblPicSize.Caption := Format('%.1n KB (%d bytes)',[Filesize / 1024,Filesize]);
- case SelImage.Bitmap.BitmapInfo.bmiHeader.biBitCount of
- 8: lblPicPal.Caption := 'Low-Color (256 colors)';
- 16: lblPicPal.Caption := 'Hi-Color (65535 colors)';
- 24: lblPicPal.Caption := 'True-Color (24-bit colors)';
- 32: lblPicPal.Caption := 'True-Color (32-bit colors)';
- else lblPicPal.Caption := 'Low-Color (<256 colors)';
- end;
- ApplyButton.Enabled := not IsNew;
- customModified := True;
- finally
- btnPicSel.Enabled := True;
- btnSndSel.Enabled := True;
- end;
- end;
-
- procedure TfrmEditContact.OnSndSelClick(Sender: TObject);
- var
- Filename,Fullpath,Objectname: WideString;
- Filesize: integer;
- begin
- btnPicSel.Enabled := False;
- btnSndSel.Enabled := False;
- try
- Objectname := (Sender as TMenuItem).Hint;
- Filename := (Sender as TMenuItem).Caption;
- Filesize := (Sender as TMenuItem).Tag;
- Fullpath := ExePath+'data\'+Form1.PhoneIdentity+'\snd\';
-
- lblSndType.Caption := '';
- lblSndSize.Caption := '';
- lblSndName.Caption := '(Loading '+Filename+'...)';
-
- try
- ForceDirectories(Fullpath);
- if Form1.FConnected and Form1.FUseObex and not FileExists(Fullpath+Filename) then
- Form1.ObexGetFile(Fullpath+Filename,Objectname,False);
-
- MediaPlayer1.FileName := Fullpath+Filename;
- MediaPlayer1.Enabled := True;
- except
- btnSndDel.Click;
- raise;
- end;
-
- lblSndName.Caption := Filename;
- lblSndSize.Caption := Format('%.1n KB (%d bytes)',[Filesize / 1024,Filesize]);
- try
- MediaPlayer1.Open;
- lblSndType.Caption := Format('Track length is %d samples (Custom format)',[MediaPlayer1.TrackLength[1]]);
- btnSndDel.Enabled := True;
- except
- lblSndType.Caption := 'Unknown (Unsupported format)';
- MediaPlayer1.Enabled := False;
- end;
- ApplyButton.Enabled := not IsNew;
- customModified := True;
- finally
- btnPicSel.Enabled := True;
- btnSndSel.Enabled := True;
- end;
- end;
-
- procedure TfrmEditContact.btnPicDelClick(Sender: TObject);
- begin
- if lblPicName.Caption <> '' then begin
- ApplyButton.Enabled := not IsNew;
- customModified := True;
- end;
- lblPicDim.Caption := '128x127 (0x0 pixels)';
- lblPicName.Caption := '';
- lblPicSize.Caption := '0,0 KB (0 bytes)';
- lblPicPal.Caption := 'Hi-Color (65535 colors)';
- SelImage.Bitmap.Clear;
- IsCustomImage := False;
- btnPicDel.Enabled := False;
- end;
-
- procedure TfrmEditContact.btnSndDelClick(Sender: TObject);
- begin
- if lblSndName.Caption <> '' then begin
- ApplyButton.Enabled := not IsNew;
- customModified := True;
- end;
- lblSndType.Caption := '(polyphonic stereo sound, supported by phone)';
- lblSndName.Caption := '';
- lblSndSize.Caption := '0,0 KB (0 bytes)';
- MediaPlayer1.Close;
- MediaPlayer1.Enabled := False;
- btnSndDel.Enabled := False;
- end;
-
- procedure TfrmEditContact.UpdatePersonalize;
- var
- m: TMenuItem;
- f: TFileStream;
- amod,cmod,OldApply: boolean;
- procedure LoadFile(fname: string; ftype: byte);
- var
- dir: string;
- begin
- { Emulate popup menu click here in order to select default
- contact picture/sound file. }
- case ftype of
- 0: dir := '\pic\';
- 1: dir := '\snd\';
- end;
- m := TMenuItem.Create(nil);
- try
- m.Caption := fname;
- try
- f := TFileStream.Create(ExePath+'data\'+Form1.PhoneIdentity+dir+fname,fmOpenRead);
- try
- m.Tag := f.Size;
- finally
- f.Free;
- end;
- except
- m.Tag := 0;
- end;
- case ftype of
- 0: OnPicSelClick(m);
- 1: OnSndSelClick(m);
- end;
- finally
- m.Free;
- end;
- end;
- begin
- OldApply := ApplyButton.Enabled;
- { Show window while updateing }
- TabSheet2.Update;
- amod := Modified;
- cmod := customModified;
- { Load personalization files on tabsheet enter }
- if (lblPicName.Caption = '') and (contact.picture <> '') then
- LoadFile(contact.picture,0);
- if (lblSndName.Caption = '') and (contact.sound <> '') then
- LoadFile(contact.sound,1);
- Modified := amod;
- customModified := cmod;
- ApplyButton.Enabled := OldApply;
- end;
-
- procedure TfrmEditContact.MediaPlayer1Click(Sender: TObject;
- Button: TMPBtnType; var DoDefault: Boolean);
- begin
- if Button = btStop then MediaPlayer1.Rewind;
- end;
-
- procedure TfrmEditContact.PageControl1Change(Sender: TObject);
- begin
- case PageControl1.ActivePageIndex of
- 1: UpdatePersonalize;
- 2: UpdateDefNum;
- end;
- end;
-
- procedure TfrmEditContact.Set_UseOwnMode(const Value: boolean);
- var
- i: integer;
- begin
- FUseOwnMode := Value;
- { In Edit Own Card mode leave only General tab visible }
- for i := 1 to PageControl1.PageCount-1 do
- PageControl1.Pages[i].TabVisible := not FUseOwnMode;
- end;
-
- procedure TfrmEditContact.btnUploadClick(Sender: TObject);
- var
- m: TMenuItem;
- ObjType: integer;
- begin
- btnPicNew.Enabled := False;
- btnSndNew.Enabled := False;
- try
- ObjType := TButton(Sender).Tag;
- Form1.RequestConnection;
- Form1.ActionToolsUpload.Execute;
- m := TMenuItem.Create(nil);
- try
- m.AutoHotkeys := maManual;
- m.Caption := ExtractFileName(Form1.OpenDialog1.FileName);
- m.Hint := Form1.FindObexFolderName(ObjType)+'/'+m.Caption;
- if ObjType = 0 then m.OnClick := OnPicSelClick
- else m.OnClick := OnSndSelClick;
- m.Click;
- finally
- m.Free;
- end;
- finally
- btnPicNew.Enabled := True;
- btnSndNew.Enabled := True;
- end;
- end;
-
- procedure TfrmEditContact.DoSanityCheck;
- var
- TelCnt: integer;
- begin
- { check name }
- if Trim(txtName.Text) = '' then
- raise EConvertError.Create('You have to enter contact name');
- if Pos('"',txtName.Text) <> 0 then begin
- if FUseSIMMode then
- raise EConvertError.Create('Quotes are not allowed in SIM contact name');
- end;
- if Trim(txtDisplayAs.Text) = '' then
- txtDisplayAs.Text := txtName.Text;
- { check numbers }
- TelCnt := 0;
- if txtCell.Text <> '' then inc(TelCnt);
- if txtHome.Text <> '' then inc(TelCnt);
- if txtWork.Text <> '' then inc(TelCnt);
- if txtFax.Text <> '' then inc(TelCnt);
- if txtOther.Text <> '' then inc(TelCnt);
- if TelCnt = 0 then
- raise EConvertError.Create('You have to enter contact phone number');
- if FUseSIMMode and (TelCnt > 1) then
- raise EConvertError.Create('You have to enter only one phone number');
- end;
-
- procedure TfrmEditContact.FillDisplayNameList;
- var
- w,s: WideString;
- i: integer;
- begin
- txtDisplayAs.Items.Clear;
- if txtName.Text <> '' then begin
- { Move surname in front }
- w := txtName.Text;
- i := Length(w);
- while (i >= 1) and (w[i] <> ' ') do dec(i);
- s := Copy(w,1,i-1);
- w := Copy(w,i+1,Length(w));
- if s <> '' then w := w + ', ' + Trim(s);
- { Fill list }
- txtDisplayAs.Items.Add(txtName.Text);
- if txtOrganization.Text <> '' then
- txtDisplayAs.Items.Add(txtName.Text + ' ' + txtOrganization.Text);
- if WideCompareText(w,txtName.Text) <> 0 then begin
- txtDisplayAs.Items.Add(w);
- if txtOrganization.Text <> '' then
- txtDisplayAs.Items.Add(w + ' ' + txtOrganization.Text);
- end;
- if txtTitle.Text <> '' then begin
- txtDisplayAs.Items.Add(txtTitle.Text + ' ' + txtName.Text);
- if txtOrganization.Text <> '' then
- txtDisplayAs.Items.Add(txtTitle.Text + ' ' + txtName.Text + ' ' + txtOrganization.Text);
- if WideCompareText(w,txtName.Text) <> 0 then begin
- txtDisplayAs.Items.Add(txtTitle.Text + ' ' + w);
- if txtOrganization.Text <> '' then
- txtDisplayAs.Items.Add(txtTitle.Text + ' ' + w + ' ' + txtOrganization.Text);
- end;
- end;
- end;
- end;
-
- procedure TfrmEditContact.ShowFullName(Modified: WideString);
- var
- s,w: WideString;
- i,j: integer;
- begin
- s := Trim(txtName.Text);
- if txtDisplayAs.Text = '' then
- txtDisplayAs.Text := s;
- { Update DisplayAs default patterns }
- w := txtDisplayAs.Text;
- i := txtDisplayAs.Items.IndexOf(w);
- { Remove any emptied field }
- if (FPrevChangeAs <> '') and (Modified = '') then begin
- j := Pos(' '+FPrevChangeAs,w);
- if j = 0 then
- j := Pos(FPrevChangeAs+' ',w);
- if j <> 0 then
- Delete(w,j,Length(FPrevChangeAs)+1);
- end;
- { Update predefined values }
- FillDisplayNameList;
- if i <> -1 then begin
- { Predefined value was used, so update it with new fields }
- j := txtDisplayAs.Items.IndexOf(w);
- if j <> -1 then
- { unused field has been changed or field is emptied }
- i := j;
- { do not remove next sanity check, its used when an used field is changed }
- if (i >= 0) and (i < txtDisplayAs.Items.Count) then
- { Set to new predefined value }
- txtDisplayAs.ItemIndex := i;
- end;
- { Udate dialog caption }
- if s <> '' then
- if FUseOwnMode then
- Caption := 'Own Business Card - '+s
- else
- Caption := 'Contact - '+s
- else
- Caption := 'Contact';
- end;
-
- procedure TfrmEditContact.txtChangeEditAs(Sender: TObject);
- var
- w: WideString;
- begin
- if not FLoadingData then begin
- w := (Sender as TTntEdit).Text;
- ShowFullName(w);
- FPrevChangeAs := w;
- end;
- ApplyButton.Enabled := not IsNew;
- Modified := True;
- end;
-
- procedure TfrmEditContact.OnChangeAsEnter(Sender: TObject);
- begin
- FPrevChangeAs := (Sender as TTntEdit).Text;
- end;
-
- procedure TfrmEditContact.LoadAndMergeWith(AContact: TContactData);
- var
- w: WideString;
- begin
- LoadContactData;
- txtTitle.Text := AContact.title;
- w := AContact.name;
- if AContact.surname <> '' then
- w := w + ' ' + AContact.surname; // do not use GetContactFullName here!
- txtName.Text := w;
- txtFileAs.Text := AContact.displayname;
- txtOrganization.Text := AContact.org;
- txtEmail.Text := AContact.email;
- txtHome.Text := AContact.home;
- txtWork.Text := AContact.work;
- txtCell.Text := AContact.cell;
- txtFax.Text := AContact.fax;
- txtOther.Text := AContact.other;
- // - Do not copy displayname, it will be merged
- // txtDisplayAs.Text := AContact.displayname;
- // - Keep old GUID!
- // txtContactDataID.Text := GUIDToString(contact.CDID);
- // - Do not copy personalization!
- // cbDefaultNum.ItemIndex := AContact.DefaultIndex;
- // lblPicName.Caption := AContact.picture;
- // lblSndName.Caption := AContact.sound;
- end;
-
- procedure TfrmEditContact.Button1Click(Sender: TObject);
- var SynchronizeContacts: TSynchronizeContacts;
- Fullpath: String;
- ID: String;
- begin
- try
- ID := Form1.PhoneIdentity;
- Fullpath := ExePath;
- if ID <> '' then
- Fullpath := ExePath+'data\'+ID+'\dat\';
-
- SynchronizeContacts := TSynchronizeContacts.Create;
- try
- SynchronizeContacts.FileName := Fullpath + 'ContactSync.xml';
-
- SynchronizeContacts.OnError := SyncContactsError;
- SynchronizeContacts.OnConfirm := SyncContactsConfirm;
-
- SynchronizeContacts.Unlink(Contact.CDID);
- finally
- SynchronizeContacts.Free;
- end;
- except
- on E: Exception do begin
- SyncLogFmt('Error: Unlink aborted (%s: %s)', [E.ClassName, E.Message]);
- Form1.Status(Format('Error: Unlink aborted (%s: %s)', [E.ClassName, E.Message]));
- MessageDlg(Format('Error: Unlink aborted (%s: %s)', [E.ClassName, E.Message]), mtError, [mbOk], 0);
- end;
- end;
- end;
-
- procedure TfrmEditContact.SyncContactsError(Sender: TObject; const Message: String);
- begin
- SyncLogFmt('Error: Unlink aborted (%s)', [Message]);
- Form1.Status(Format('Error: Unlink aborted (%s)', [Message]));
- MessageDlg(Format('Error: Unlink aborted (%s)', [Message]), mtError, [mbOk], 0);
- end;
-
- resourcestring
- SSyncContactsConfirm = '%s.' +
- #13#10 + #13#10 +
- 'Is this ok?';
-
- procedure TfrmEditContact.SyncContactsConfirm(Sender: TObject; Contact: TContact;
- Action: TContactAction; const Description: WideString; var Confirmed:
- Boolean);
- begin
- Confirmed := MessageDlg(WideFormat(SSyncContactsConfirm, [Description]), mtConfirmation, [mbNo, mbYes], 0) = mrYes;
- end;
-
- procedure TfrmEditContact.btNotesClearClick(Sender: TObject);
- begin
- MemoNotes.Clear;
- MemoNotesChange(nil);
- end;
-
- procedure TfrmEditContact.MemoNotesChange(Sender: TObject);
- begin
- btNotesSave.Enabled := Trim(MemoNotes.Text) <> '';
- btNotesClear.Enabled := btNotesSave.Enabled;
- { SaveSettings will store changes in database, so we dont need
- to set modified flags here }
- ApplyButton.Enabled := True;
- end;
-
- procedure TfrmEditContact.btNotesSaveClick(Sender: TObject);
- begin
- if SaveDialog1.FileName = '' then
- SaveDialog1.FileName := txtName.Text + '.txt';
- if SaveDialog1.Execute then
- MemoNotes.Lines.SaveToFile(SaveDialog1.FileName);
- end;
-
- procedure TfrmEditContact.Set_CustomImage(const Value: Boolean);
- begin
- FCustomImage := Value;
- if not Value then
- SelImage.Bitmap.Assign(Form1.CommonBitmaps.Bitmap[0]);
- end;
-
- procedure TfrmEditContact.txtEmailChange(Sender: TObject);
- begin
- ApplyButton.Enabled := not IsNew;
- Modified := True;
- end;
-
- end.
-